/*
 * SplitVecCase.cpp
 *
 *  Created on: 2012-9-8
 *      Author: yangentao@gmail.com
 */

#include "test.h"
#include "../src/yet/SplitVec.h"
using namespace  yet;
TEST(SplitVec, constructor1) {
	SplitVec<char> v;
	EXPECT_EQ(v.length(), 0);
}

TEST(SplitVec, constructor2) {
	SplitVec<char> v(8);
	EXPECT_EQ(v.length(), 0);
}

TEST(SplitVec, constructor3) {
	SplitVec<char> v;
	v.append("abc", 3);
	EXPECT_EQ(v.length(), 3);
	EXPECT_TRUE(v.equals("abc", 3));
}

TEST(SplitVec, constructor4) {
	SplitVec<char> v;
	v.append("abc", 3);
	EXPECT_EQ(v.length(), 3);

	SplitVec<char> v2(v);
	EXPECT_EQ(v2.length(), 3);
	EXPECT_TRUE(v2.equals(v2));
}
TEST(SplitVec, operatorEQ) {
	SplitVec<char> v;
	v.append("abc", 3);
	EXPECT_EQ(v.length(), 3);

	SplitVec<char> v2;
	v2 = v;
	EXPECT_EQ(v2.length(), 3);
	EXPECT_TRUE(v2.equals(v2));
}

TEST(SplitVec, copyFrom) {
	SplitVec<char> v;
	v.append("abc", 3);
	EXPECT_EQ(v.length(), 3);

	SplitVec<char> v2;
	v2.copyFrom(v);
	EXPECT_EQ(v2.length(), 3);
	EXPECT_TRUE(v2.equals(v2));
}

TEST(SplitVec, ensureCapcity) {
	SplitVec<char> v;
	v.append("abc", 3);
	v.ensureCapcity(32);
	EXPECT_GE(v.getCapcity(), 32);

}
TEST(SplitVec, get) {
	SplitVec<char> v;
	v.append("abc", 3);
	v.insert(1, 'b');
	EXPECT_EQ(v.get(0), 'a');
	EXPECT_EQ(v.get(1), 'b');
	EXPECT_EQ(v.get(2), 'b');
	EXPECT_EQ(v.get(3), 'c');

	EXPECT_EQ(v[0], 'a');
	EXPECT_EQ(v[1], 'b');
	EXPECT_EQ(v[2], 'b');
	EXPECT_EQ(v[3], 'c');
}

TEST(SplitVec, set) {
	SplitVec<char> v;
	v.append("abc", 3);
	v.insert(1, 'x');
	v.remove(1);
	v[0] = 'A';
	EXPECT_TRUE(v.equals("Abc", 3));
}
TEST(SplitVec, firstLast) {
	SplitVec<char> v;
	v.append("abc", 3);
	v.insert(1, 'x');
	v.remove(1);
	v[0] = 'A';
	EXPECT_EQ(v.first(), 'A');
	EXPECT_EQ(v.last(), 'c');
}
TEST(SplitVec, getRange) {
	SplitVec<char> v;
	v.append("abc", 3);
	char* buf = new char[3];
	v.getRange(buf, 1, 1);
	EXPECT_EQ(buf[0], 'b');
}

TEST(SplitVec, append) {
	SplitVec<char> v;
	v.append("abc", 3);
	v.append("de", 2);
	EXPECT_TRUE(v.equals("abcde", 5));
}

TEST(SplitVec, insert) {
	SplitVec<char> v;
	v.append("abc", 3);
	v.insert(1, "de", 2);

	EXPECT_TRUE(v.equals("adebc", 5));
}

TEST(SplitVec, remove) {
	SplitVec<char> v;
	v.append("abc", 3);
	v.remove(1);
	v.remove(1, 1);
	EXPECT_TRUE(v.equals("a", 1));
}

TEST(SplitVec, replace) {
	SplitVec<char> v;
	v.append("abc", 3);
	v.replace(1, 1, "B", 1);
	v.replace(0, 1, "A", 1);
	EXPECT_TRUE(v.equals("ABc", 3))<<string(v.getBuffer(), v.length());
}


